package com.bwie.gddproject.xiangqing.precenter;

import com.bwie.gddproject.net.OnNetLitenner;
import com.bwie.gddproject.xiangqing.model.IsAddBean;
import com.bwie.gddproject.xiangqing.view.IXiangQingActivity;
import com.bwie.gddproject.xiangqing.model.IXiangQingModel;
import com.bwie.gddproject.xiangqing.model.XiangQingBean;
import com.bwie.gddproject.xiangqing.model.XiangQingModel;

/**
 * Created by 我走路带风 on 2017/12/15.
 */

public class XiangQingPrecenter implements IXiangQingPrecenter{
    private IXiangQingModel xiangQingModel;
    private IXiangQingActivity xiangQingActivity;
    private String pid;

    public XiangQingPrecenter(IXiangQingActivity xiangQingActivity) {
        this.xiangQingActivity = xiangQingActivity;
        xiangQingModel = new XiangQingModel();
    }

    @Override
    public void getGood() {
        pid = xiangQingActivity.getPid();
        xiangQingModel.getGood(new OnNetLitenner<XiangQingBean>() {
            @Override
            public void success(XiangQingBean xiangQingBean) {
                xiangQingActivity.showGood(xiangQingBean);
            }

            @Override
            public void fail(String errer) {
                xiangQingActivity.toast(errer);
            }

        }, pid);
    }

    @Override
    public void isAdd() {
        xiangQingModel.addCar(new OnNetLitenner<IsAddBean>() {
            @Override
            public void success(IsAddBean isAddBean) {
                if (isAddBean.getCode().equals("0")){
                    xiangQingActivity.toast("加购成功");
                }else{
                    xiangQingActivity.toast("加购失败");
                }
            }

            @Override
            public void fail(String errer) {
                xiangQingActivity.toast("加购失败");
            }
        },pid);
    }
}
